from sklearn import datasets
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

loaded_data = datasets.load_boston()
data_x = loaded_data.data
data_y = loaded_data.target

model = LinearRegression()
model.fit(data_x, data_y)

print(model.predict(data_x[:4, :]))
print(data_y[:4])
print(model.coef_)  # 每个特征x前的系数，y=coef_x + intercept_
print(model.intercept_)  # 线性回归中的常数,与y轴的焦点
print(model.get_params())  # 设置了哪些参数
print(model.score(data_x, data_y))  # 对预测值与真实值打分

# x, y = datasets.make_regression(n_samples=100, n_features=1, n_targets=1, noise=1)
# plt.scatter(x, y)
# plt.show()
